<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>实现深拷贝</title>
</head>

<body>
    <script>
        function copyobj(obj) {
            let obj1 = Array.isArray(obj) ? {} : []
            for (let key in obj) {
                if(typeof obj[key] == 'object'){
                    obj1[key] ==  copyobj(obj[key])          
                }else{
                    obj1[key] == obj[key]
                }
            }
            return obj1
        }
        let obj = { name: '张三', age: '20', hobby: ['打篮球', '踢足球', '唱歌', '跳舞'] }
        let obj1 = copyobj(obj);
        obj.hobby.push('跑步');
        console.log(obj, obj1);
    </script>
</body>

</html>